package com.lhy.controller;

import com.lhy.pojo.Record;
import com.lhy.service.RecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("record")
public class RecordsController {
    @Resource
    private RecordService recordService;

    //添加气体信息到mongodb
    @PostMapping("add")
    public String addMiner(Record record){
        recordService.addRecord(record);
        return "添加成功";
    }

    //查询所有
    @GetMapping("list")
    public Map<String,Object> selectRecordList(){
        return recordService.selectRecordList();
    }

    //根据气体编号删除气体信息
    @PostMapping("delete")
    public String deleteRecordById(String gasId){
        recordService.deleteRecordById(gasId);
        return "删除成功";
    }

    //根据气体编号修改气体信息
    @PostMapping("update")
    public String updateRecordInfo(Record record){
        recordService.updateRecordInfo(record);
        return "修改成功";
    }

    //通过气体名称查询
    @GetMapping("{gasName}")
    public Record selectRecordByName(@PathVariable String gasName){
        return recordService.selectRecordByName(gasName);
    }

}
